/****************************************************
	文件：NormalSeek.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/5/15 23:30:42
	功能：常规的Seek行为
*****************************************************/

using UnityEngine;

namespace AIBehavior
{
    public class NormalSeek : Decorator
    {
        private Vector3 mCurrentVelocity;

        public NormalSeek(AIData data) : base(data) { }

        public override void Init(AIData data)
        {
            mCurrentVelocity = new Vector3(1 * mData.MaxVelocity, 0, 0);  //初始速度
        }
        protected override void DoSelf()
        {
            if (Vector3.SqrMagnitude(GameRoot.Instance.Pos.Value - mData.SelfTrans.transform.position) < Consts.MIN_ERROR_DELTA) return;

            mCurrentVelocity = Vector3.Normalize(GameRoot.Instance.Pos.Value - mData.SelfTrans.transform.position) * mData.MaxVelocity;
            mData.SelfTrans.transform.position += mCurrentVelocity * Time.fixedDeltaTime;

            mData.CurrentVelocity = mCurrentVelocity;
        }
    }
}